package org.opens.mybatisplus.entity.enumObj3;


import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;

/**
 * 说明:
 *      1. 作用与spring mvc匹配到请求后, 被@RequestBody修饰的对象参数做转换的过程.
 */
public class EnumObj3JsonConvter implements Converter<Integer, EnumObj3Sex> {

    @Override
    public EnumObj3Sex convert(Integer value) {
        return EnumObj3Sex.getEnumObjByValue(value);
    }

    /**
     * 功能:
     *      规定json参数输入值类型.
     */
    @Override
    public JavaType getInputType(TypeFactory typeFactory) {
        return typeFactory.constructType(Integer.class);
    }

    /**
     * 功能:
     *      规定json参数转换输出值类型.
     */
    @Override
    public JavaType getOutputType(TypeFactory typeFactory) {
        return typeFactory.constructType(EnumObj3Sex.class);
    }
}
